package ldh.im.web.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtil {

    public static boolean isEmail(String str) {
        if (str == null) return false;
        String regEx = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        if(m.matches()){
            return true;
        }
        return false;
    }

    public static boolean isPhone(String str) {
        if (str == null) return false;
        String regex = "^1[3|4|5|7|8][0-9]\\d{4,8}$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);
        if(m.matches()){
            return true;
        }
        return false;
    }
}
